<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%@page import="java.sql.Connection"%>
<%@page import="com.yuxin.common.util.DBUtil"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Map"%>
<%@page import="java.net.URLDecoder"%>
<%@page import="com.yuxin.common.util.CommonUtil"%>
<%
	Connection conn = null;
	String id = request.getParameter("id");
	Map<String, Object> orderMap = null;
	List<Map<String, Object>> orderGoodsList = null;
	String o_status = "";
	try {
		if(!CommonUtil.isLoginValid(request)){
			response.sendRedirect(request.getContextPath()+"/site/denglu.jsp");
			return;
		 }
		conn = DBUtil.getConnection();
		 // 页面标题
        request.setAttribute("titleName",URLDecoder.decode("订单详情", "UTF-8"));
		
		String sql = "select t.ID, t.CODE, t.TOTAL_PRICE, DATE_FORMAT(t.CREATE_TIME, '%Y-%m-%d %H:%i') as CREATETIME, t.STATUS,"
					  + " DATE_FORMAT(t.PAY_TIME, '%Y-%m-%d %H:%i') as PAYTIME, DATE_FORMAT(t.SHIPPING_TIME, '%Y-%m-%d %H:%i') as SHIPPINGTIME,"
					  + " DATE_FORMAT(t.TRANSACTION_TIME, '%Y-%m-%d %H:%i') as TRANSACTIONTIME"
					 +" from p_orders t where t.ID = ?";
		orderMap = DBUtil.queryUniqueResult(conn, sql, id);
		o_status = orderMap.get("STATUS").toString();
		
		sql = "select t.GOODS_IMG, t.GOODS_NAME, t.GOODS_PRICE from p_order_goods t where t.ORDER_ID = ?";
		orderGoodsList = DBUtil.queryList(conn, sql, id);
	} catch (Exception ex) {
		ex.printStackTrace();
	} finally {
		DBUtil.close(conn);
	}
%>
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>${titleName}</title>
        <meta name="Keywords" content="中信信用卡平台" />
        <meta name="Description" content="${titleName}"/>
        <meta name="robots" content="all"/>
        <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes"/>
        <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
        <meta name="format-detection" content="telephone=no"/>
        <meta http-equiv="cleartype" content="on"/>
        <link rel="icon" type="image/png" href="images/favicon.ico">
        <%@ include file="/site/css.jsp" %>
        <style type="text/css">
			.biaoge{margin-top:10px;width:100%;background-color:#fff;overflow:hidden;border:1px solid #C6C4C2;line-height:24px;-webkit-border-radius: .2em;-moz-border-radius: .2em;border-radius: .2em;}
			.biaoge li{list-style-type: none;color:#666;padding:1px 10px;border-bottom:1px solid #C6C4C2;line-height:30px;overflow:hidden;}
			.biaoge li:last-child{border-bottom: none;}
			.biaoge .name{float:left;}
			.biaoge .value{float:right;}
		</style>
	</head>
	<body>
        <div id="page">
            <%@ include file="/site/header_nav.jsp" %>
            <div id="container">
            	<ul class="biaoge">
                    <li><div class="name">订单编号</div><div class="value"><%=orderMap.get("CODE") %></div></li>
                    <li><div class="name">订单状态</div><div class="value">
						<%="1".equals(o_status) ? "未付款" : "2".equals(o_status) ? "等待卖家发货" : "3".equals(o_status) ? "卖家已发货" : 
                		"4".equals(o_status) ? "退款中" : "5".equals(o_status) ? "交易成功" : "交易关闭" %></div></li>
                    <li>
                    	<div class="name">
                    		<%="1".equals(o_status) ? "下单时间" : "2".equals(o_status) ? "付款时间" : "3".equals(o_status) ? "发货时间" : 
                            	"5".equals(o_status) ? "收货时间" : "成交时间" %>
                    	</div>
                       <div class="value">
                       		 <%="1".equals(o_status) ? orderMap.get("CREATETIME") : "2".equals(o_status) ? orderMap.get("PAYTIME") :  
                            	"3".equals(o_status) ? orderMap.get("SHIPPINGTIME") : 
                            	"5".equals(o_status) ? orderMap.get("TRANSACTIONTIME") : orderMap.get("CREATETIME")%>
                       </div></li>
                    <li><div class="name">订单金额</div><div class="value"><%=orderMap.get("TOTAL_PRICE") %>元</div></li>
                </ul>           	            	
              <%
			  	if(orderGoodsList == null || orderGoodsList.size() == 0) {
			  		out.println("<div style='margin-top:10px; text-align:center;'>暂无记录！</div>");
			  	} else {
				%>	
                  <ul class="biaoge">
              <%   
			  	for(Map<String, Object> map : orderGoodsList) {
			  %>
                    <li>
                    	<div class="name" style="margin:3px; width:40%;"><img src="<%=request.getContextPath() %>/<%=map.get("GOODS_IMG") %>" width="100" /></div>
                        <div class="value" style="float:left; width:55%;">
                        	<div><%=map.get("GOODS_NAME") %></div> 
                            <div>&nbsp;</div>
                            <div><%=map.get("GOODS_PRICE") %></div>
                        </div>
                    </li>
                
            <%
				}
			%>
            	</ul> 	
			<% 
              }	
            %>
            </div>
            <%@ include file="/site/footer.jsp" %>
        </div>
    </body>
</html>